/******************************************************************************
*
* This file is part of FreeTrack (http://code.google.com/p/qtfreetrack).
* BY Willy Gardiol (willy@gardiol.org)
*
* FreeTrack is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* FreeTrack is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar.  If not, see <http://www.gnu.org/licenses/>
*
******************************************************************************/

#ifndef WORKERPROCESS_H
#define WORKERPROCESS_H

#include <QtGui>
#include "controls/rotatingdialog.h"

class FTLabel;
class FTIconLabel;
class FTPushButton;

class WorkerProcess : public RotatingDialog
{
    Q_OBJECT
public:
    // Say true when do_stuff has terminated
    bool isTerminated();
    QString getErrorString();

    bool run();

public slots:
    void pleaseTerminate();

protected:
    explicit WorkerProcess(int, const QString& title);

    // will be true when a termination is requested
    bool please_terminate;

    virtual bool do_stuff();

    void setErrorString(const QString&);

    void setMinMaxProgress(int max, int mmin = 0);
    void updateProgress(int value);
    void updateText(int, const QString&);

    void updateTextProgress(int, const QString &, int );

private:
    bool still_running;
    bool error;
    QString error_string;

    int progressRange;
    int progressValue;

    FTLabel* wait_title;
    FTIconLabel* wait_icon;
    QProgressBar* wait_progress;
    QList<FTLabel*> wait_progress_labels;
    int nLabels;
    FTPushButton* wait_cancel;

    QLayout* createVertical();
};

#endif // WORKERPROCESS_H
